/* ---------------------------------------------------------------------------
   (c) Copyright 2006 ActivIdentity, Inc.
   All Rights Reserved.

   This program is an unpublished copyrighted work which is proprietary
   to ActivIdentity. This computer program includes Confidential,
   Proprietary Information and is a Trade Secret of ActivIdentity.
   Any use, disclosure, modification and/or reproduction is prohibited
   unless authorized in writing by ActivIdentity.

   WARNING:  Unauthorized reproduction of this program as well as
   unauthorized preparation of derivative works based upon the
   program or distribution of copies by sale, rental, lease or
   lending are violations of federal copyright laws and state trade
   secret laws, punishable by civil and criminal penalties.
   --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
   Disclaimer

   ACTIVIDENTITY MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE 
   CONTENTS OR USE OF THIS SOFTWARE, AND SPECIFICALLY DISCLAIMS ANY EXPRESS
   OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
   PURPOSE. Further, ActivIdentity reserves the right to revise this software
   and to make changes to its content, at any time, without obligation to
   notify any person or entity of such revisions or changes.
   --------------------------------------------------------------------------- */

#ifndef _ACTOKEN_H_

#define _ACTOKEN_H_


#ifdef __cplusplus 
extern "C" {
#endif
/* constants length */
#define TOKEN_SN_LEN				37
#define TOKEN_INIT_DATE_LEN			19
#define TOKEN_TAG_LEN				20
#define TOKEN_KEY_DES_LEN			16
#define TOKEN_KEY_DES3_LEN			32
#define TOKEN_PRO_UID_LEN			40
#define TOKEN_NAME_LEN				20
#define TOKEN_PRO_FCT_LEN			20
#define TOKEN_PRO_KEYTYPE_LEN		100
#define TOKEN_PIN_LEN				8
#define TOKEN_UNLOCKPHONE_LEN		12
#define TOKEN_RESERVED_LEN			20
#define TOKEN_ACTIV_CODE_LEN		4
#define TOKEN_USER_ID_LEN			20
#define TOKEN_SLOT_NAME				12
#define TOKEN_MESS_NAME				12
#define TOKEN_PHONE_LEN				20
#define TOKEN_MAX_CERT_FIELD		16


/* Token parameters */

typedef struct
{
	/* Identification	*/
	char aTokSN[TOKEN_SN_LEN+1];			/* Serial Number (production) */
	int lTokMask;							/* Token type : 4/5/6/7/8/9 */
	int lTokenOffset;						/* token offset */
	char aTokDtInit[TOKEN_INIT_DATE_LEN+1];	/* 1st init date */
	char aTokTag[TOKEN_TAG_LEN+1];			/* Initialisation tag */

	/* Data created during initialization	*/
	/* The keys are in ASCII hexa	*/
	char aInitKey[TOKEN_KEY_DES_LEN+1];		/* Init key KF */
	char aResetKey[TOKEN_KEY_DES_LEN+1];	/* Reset key (only 5P) */
	char aUpdKey[TOKEN_KEY_DES_LEN+1];		/* Update key (only 4S) */
	char aUnlKey[TOKEN_KEY_DES_LEN+1];		/* Unlock key */
	char aCnfDKey[TOKEN_KEY_DES_LEN+1];		/* Conf data key */
	char aCnfDCypKey[TOKEN_KEY_DES_LEN+1];	/* Conf data ciphered (only 5P)	*/
	char aMemoKey[TOKEN_KEY_DES_LEN+1];		/* Memo key (only 5P) */
	char aSlot1IKey[TOKEN_KEY_DES_LEN+1];	/* Slot 1 init key */
	char aSlot2IKey[TOKEN_KEY_DES_LEN+1];	/* Slot 2 init key */
	char aSlot3IKey[TOKEN_KEY_DES_LEN+1];	/* Slot 3 init key */
	char aSlot4IKey[TOKEN_KEY_DES_LEN+1];	/* Slot 4 init key */

	/* Token profile data */
	char aProUId[TOKEN_PRO_UID_LEN+1];		/* Token profile UID */
	char aProName[TOKEN_NAME_LEN+1];		/* Token profile name */
	char aProFct[TOKEN_PRO_FCT_LEN+1];		/* Token rights/fct 1:Certif */
	char aProKeyType[TOKEN_PRO_KEYTYPE_LEN+1];/* Array of key type ??									*/
	int lSlotCurr;							/* Current slot[1]/[2]/[3]/[4](only 5P)	*/

	/* General data */
	char aGName[TOKEN_NAME_LEN+1];			/* General Data group name */
	char cDESType;							/* DES type [1]/[3] (only t9) */
	char cPinInitMode;						/* PIN: Init mode [F]ix/[R]andom */
	char aPinInitVal[TOKEN_PIN_LEN+1];		/* PIN: Init value */
	int lPinLnMin;							/* PIN: length max 4-8 >= Max */
	int lPinLnMax;							/* PIN: length min 4-8 <= Min */
	int lPinWeak;							/* PIN: Weak pin control (0/1) */
	int lPinErrMax;							/* PIN: Err max nb (1-9) */
	int lPinErrInit;						/* PIN: Err init nb (<= PinErrMax) */
	int lPinChg;							/* Pin: User can change (0/1) (only 5P)*/
	int lUnlErrMax;							/* Unlock: unl code err max nb (1-9) */
	int lUnlErrInit;						/* Unlock: err init nb (<= UnlErrMax)   */
	int lUnlChalCkD;						/* Unlock: chal check dg (0/1) (only 4S)*/
	int lUnlRespCkD;						/* Unlock: resp check dg (0/1) (only 4S)*/
	int lUnlPinChg;							/* Unlock: user can chg  (0/1) (only 5P)*/
	char aUnlPhone[TOKEN_UNLOCKPHONE_LEN+1];/* Unlock: DTMF Phone nb (only 5P) */
	int lUnlDTMF;							/* Unlock: DTMF available(0/1) (only 5P)*/
	int lUnlDTime;							/* Unlock: DTMF time (60-90) (only 5P)*/
	int lPowerTO;							/* Power time out (sec)(10-60) (only 5P)*/
	char aMsgName[TOKEN_NAME_LEN+1];		/* Message group name	*/
	char TokFd1[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd2[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd3[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd4[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd5[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd6[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd7[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd8[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd9[TOKEN_RESERVED_LEN+1];		/* Not used */
	char TokFd10[TOKEN_RESERVED_LEN+1];		/* Not used */
} strToken;

/* Slot */
typedef struct
{
	/* Identification	*/
	int lSlotNb;							/* SlotNumber */
	int lUsed;								/* Set if slot used (0/1) */
	char aDtInit[TOKEN_INIT_DATE_LEN+1];	/* 1st init date */
	char cState;							/* State:[E]mpty/[L]oaded/[A]vailable */
	char aActivCode[TOKEN_ACTIV_CODE_LEN+1];/* Activation code */

	/* Data created during initialization	*/
	/* The keys are in ASCII hexa */
	char aUpdKey[TOKEN_KEY_DES_LEN+1];		/* Update key */
	char aAuthAsyKey[TOKEN_KEY_DES3_LEN+1];	/* Async Authentication key */
	char aAuthSynKey[TOKEN_KEY_DES3_LEN+1];	/* Sync Authentication key */
	unsigned int ulAuthSynCnt;				/* Sync Authentication counter */
	char aSecretKey	[TOKEN_KEY_DES3_LEN+1];	/* Secret value extract key */
	char aSecretValue[TOKEN_KEY_DES_LEN+1];	/* Secret value (never exported) */
	char aCertAsyKey[TOKEN_KEY_DES3_LEN+1];	/* Async certification key (Only 5P)*/
	char aCertSynKey[TOKEN_KEY_DES3_LEN+1];	/* Sync certification key (Only 5P)*/
	unsigned int ulCertSynCnt;				/* Sync certification counter (Only 5P)*/
	char aVerifKey[TOKEN_KEY_DES3_LEN+1];	/* Host verification key (Only 5P)*/
	char aSlotUserId[TOKEN_USER_ID_LEN+1];	/* Slot User Id */
	char aSName[TOKEN_SLOT_NAME+1];			/* Slot Name */

	/* Slot profile data */
	char aSPName[TOKEN_NAME_LEN+1];			/* Slot Profile name */
	int lService;							/* Service display flag 0/1 */
	char cDESType;							/* DES Type [1]/[3] (only T9)*/
	int lSyncKDrv;							/* Sync deviation key 0/1 (only T9)*/
	int lSyncCInc;							/* Sync counter incr 0/1 (only T9)*/
	char cSlot_A_S;							/* Slot fct:[A]uth or [S]ecret (only 5P)*/
	char cDisplay;							/* Resp type H/D (if Secret->H)(only 5P)*/
	int lCplSh;								/* Coupler: shortcut (0/1)(only 4S)*/
	int lAuthRespLn;						/* Auth: resp ln (5/7/11/15=24/32/48/64)*/
	int lAuthRespCkD;						/* Auth: resp check (0/1)(only 4S)*/
	int lAuthChalMin;						/* Auth: chal min (4-8 <= max) */
	int lAuthChalMax;						/* Auth: chal max (4-8 >= min) */
	int lAuthChalCkD;						/* Auth: chal check (0/1) (only 4S)*/
	int lAuthSyncExt;						/* Auth: extract bit clock 2**n */
	int lAuthSyncSh;						/* Auth: sync shortcut (0/1) (only 4S)*/
	int lAuthVerif;							/* Auth: host verif (0/1) (only 5P)*/
	char cSecGenMode;						/* Secr: gener mode [M]anual/[X]9.17 */
	int lSecRespLn;							/* Secr: resp length (=15=64 bit) */
	int lSecRespCkD;						/* Secr: resp check (0/1) (only 4S)*/
	int lSecChalMin;						/* Secr: chal min (4-8 <= max) */
	int lSecChalMax;						/* Secr: chal max (4-8 >= min) */
	int lSecChalCkD;						/* Secr: chal check (0/1)(only 4S)*/
	int lSecVerif;							/* Secr: host verif (0/1)(only 5P)*/
	char cCertMode;							/* Certif: mode [A]sync/[S]ync (5P/V1) or [a]sync/[s]ync (V2-extended mode) */
	int lCertSyncExt;						/* Certif: extract bit 2**n (only 5P)*/
	int lCertRespLn;						/* Certif: (5/7/11/15=24/32/48/64)  (5P)*/
	int lCertVerif;							/* Certif: host verif (0/1) (only 5P)*/
	int lCertMin[5];						/* Certif: min ln (0-23<=mx) (only 5P)*/
	int lCertMax[5];						/* Certif: mx(0-23<=mn sum<=64)(only 5P)*/
	int lCertPer[5];						/* Certif: period option (0/1) (only 5P)*/
	char aCertMsg[5][TOKEN_MESS_NAME+1];	/* Certif: message (only 5P)	*/
	char aPhone[TOKEN_PHONE_LEN+1];			/* Phone number */
	int lDtmfFlag;							/* DTMF:set if available (0/1) */
	char cDtmfFmt;							/* DTMF:format [H]exa/[D]ec */
	int lDtmfTime;							/* DTMF:time (65-90) */
	char cGAMode;							/* AEG Auth: mode [A]sync/[S]ync/[N]/[D]*/
	int lGAChalLn;							/* AEG Auth: chal ln (in Auth chal range)*/
	char cGARespFmt;						/* AEG Auth: [H]exa/[D]ec */
	int lGSChalLn;							/* AEG Secr: chal ln (in Secr chal range)*/

	char SlotFd1[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd2[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd3[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd4[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd5[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd6[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd7[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd8[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd9[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd10[TOKEN_RESERVED_LEN+1];	/* Not used */
} strSlot;

/* These definitions concerne Extended certification for token V2 */

/* Extended Slot */
typedef struct
{
	/* Identification	*/
	int lSlotNb;							/* SlotNumber */
	int lUsed;								/* Set if slot used (0/1) */
	char aDtInit[TOKEN_INIT_DATE_LEN+1];	/* 1st init date */
	char cState;							/* State:[E]mpty/[L]oaded/[A]vailable */
	char aActivCode[TOKEN_ACTIV_CODE_LEN+1];/* Activation code */

	/* Data created during initialization	*/
	/* The keys are in ASCII hexa */
	char aUpdKey[TOKEN_KEY_DES_LEN+1];		/* Update key */
	char aAuthAsyKey[TOKEN_KEY_DES3_LEN+1];	/* Async Authentication key */
	char aAuthSynKey[TOKEN_KEY_DES3_LEN+1];	/* Sync Authentication key */
	unsigned int ulAuthSynCnt;				/* Sync Authentication counter */
	char aSecretKey	[TOKEN_KEY_DES3_LEN+1];	/* Secret value extract key */
	char aSecretValue[TOKEN_KEY_DES_LEN+1];	/* Secret value (never exported) */
	char aCertAsyKey[TOKEN_KEY_DES3_LEN+1];	/* Async certification key (Only 5P)*/
	char aCertSynKey[TOKEN_KEY_DES3_LEN+1];	/* Sync certification key (Only 5P)*/
	unsigned int ulCertSynCnt;				/* Sync certification counter (Only 5P)*/
	char aVerifKey[TOKEN_KEY_DES3_LEN+1];	/* Host verification key (Only 5P)*/
	char aSlotUserId[TOKEN_USER_ID_LEN+1];	/* Slot User Id */
	char aSName[TOKEN_SLOT_NAME+1];			/* Slot Name */

	/* Slot profile data */
	char aSPName[TOKEN_NAME_LEN+1];			/* Slot Profile name */
	int lService;							/* Service display flag 0/1 */
	char cDESType;							/* DES Type [1]/[3] (only T9)*/
	int lSyncKDrv;							/* Sync deviation key 0/1 (only T9)*/
	int lSyncCInc;							/* Sync counter incr 0/1 (only T9)*/
	char cSlot_A_S;							/* Slot fct:[A]uth or [S]ecret (only 5P)*/
	char cDisplay;							/* Resp type H/D (if Secret->H)(only 5P)*/
	int lCplSh;								/* Coupler: shortcut (0/1)(only 4S)*/
	int lAuthRespLn;						/* Auth: resp ln (5/7/11/15=24/32/48/64)*/
	int lAuthRespCkD;						/* Auth: resp check (0/1)(only 4S)*/
	int lAuthChalMin;						/* Auth: chal min (4-8 <= max) */
	int lAuthChalMax;						/* Auth: chal max (4-8 >= min) */
	int lAuthChalCkD;						/* Auth: chal check (0/1) (only 4S)*/
	int lAuthSyncExt;						/* Auth: extract bit clock 2**n */
	int lAuthSyncSh;						/* Auth: sync shortcut (0/1) (only 4S)*/
	int lAuthVerif;							/* Auth: host verif (0/1) (only 5P)*/
	char cSecGenMode;						/* Secr: gener mode [M]anual/[X]9.17 */
	int lSecRespLn;							/* Secr: resp length (=15=64 bit) */
	int lSecRespCkD;						/* Secr: resp check (0/1) (only 4S)*/
	int lSecChalMin;						/* Secr: chal min (4-8 <= max) */
	int lSecChalMax;						/* Secr: chal max (4-8 >= min) */
	int lSecChalCkD;						/* Secr: chal check (0/1)(only 4S)*/
	int lSecVerif;							/* Secr: host verif (0/1)(only 5P)*/
	char cCertMode;							/* Certif: mode [A]sync/[S]ync/extended [a]sync/extended [s]ync (5P + One)*/
	int lCertSyncExt;						/* Certif: extract bit 2**n (5P + One)*/
	int lCertRespLn;						/* Certif: (5/7/11/15=24/32/48/64)  (5P + One)*/
	int lCertVerif;							/* Certif: host verif (0/1) (only 5P)*/
	int lCertMin[TOKEN_MAX_CERT_FIELD];		/* Certif: min ln (0-23<=mx) (5P + One)*/
	int lCertMax[TOKEN_MAX_CERT_FIELD];		/* Certif: mx(0-23<=mn sum<=64)(5P + One)*/
	int lCertPer[TOKEN_MAX_CERT_FIELD];		/* Certif: period option (0/1) (5P + One)*/
	char cPadd;								/* Certif: padding character (One V2 only)*/ 
	int nNbEffField ;						/* Certif: Number of effective certification fields (One V2 only) */
	char aCertMsg[TOKEN_MAX_CERT_FIELD][TOKEN_MESS_NAME+1];	/* Certif: message (5P + One)	*/
	char aPhone[TOKEN_PHONE_LEN+1];			/* Phone number */
	int lDtmfFlag;							/* DTMF:set if available (0/1) */
	char cDtmfFmt;							/* DTMF:format [H]exa/[D]ec */
	int lDtmfTime;							/* DTMF:time (65-90) */
	char cGAMode;							/* AEG Auth: mode [A]sync/[S]ync/[N]/[D]*/
	int lGAChalLn;							/* AEG Auth: chal ln (in Auth chal range)*/
	char cGARespFmt;						/* AEG Auth: [H]exa/[D]ec */
	int lGSChalLn;							/* AEG Secr: chal ln (in Secr chal range)*/

	char SlotFd1[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd2[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd3[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd4[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd5[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd6[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd7[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd8[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd9[TOKEN_RESERVED_LEN+1];		/* Not used */
	char SlotFd10[TOKEN_RESERVED_LEN+1];	/* Not used */
} strExtSlot;

#ifdef __cplusplus
}
#endif

#endif /* _ACTOKEN_H_ */
